package com.aiti.lulian.controller;

import com.aiti.base.core.utils.message.Message;
import com.aiti.lulian.service.ISmsCodeService;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @ClassName SmsCodeController
 * @Description
 * @Author diaozhende
 * @Date 2024/6/21 21:16
 */
@RestController
@RequestMapping("/smsCode")
public class SmsCodeController {


    @Resource
    private ISmsCodeService smsCodeService;

    /**
     * 校验验证码
     *
     * @param codeData 请求参数{code: "", phone: ""}
     * @return com.aiti.base.core.utils.message.Message
     * @date 2024/6/21 21:32
     * @author diaozhende
     */
    @PostMapping("/verifyCode")
    public Message verifyCode(@RequestBody String codeData) {
        try {
            smsCodeService.verifyCode(codeData);
        } catch (Exception e) {
            return Message.fail(e.getMessage());
        }
        return Message.success();
    }


    /**
     * 发送验证码
     * @param parameters 请求参数{phone: ""}
     * @return com.aiti.base.core.utils.message.Message
     * @date 2024/6/21 21:36
     * @author diaozhende
     */
    @PostMapping("/sendCode")
    public Message sendCode(@RequestBody JSONObject parameters){
        try {
            smsCodeService.sendCode(parameters);
        } catch (Exception e) {
            return Message.fail(e.getMessage());
        }
        return Message.success("短信可能会存在延迟，请耐心等待");
    }
}
